package system.user.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import system.user.dao.UserDao;
import system.user.dto.User;

import com.core.framework.db.IDao;
import com.core.framework.db.jdbc.BaseService;
import com.core.framework.db.jdbc.page.Page;
import com.util.AppUtils;
import com.util.SSUtils;
@Service("userService")
public class UserService extends BaseService<User> 
{
	
	@Autowired
	UserDao userDao;
	@Override
	public IDao<User, String> getDao() {
		return userDao;
	}
	public Page<User> getUserPage(Page<User> page)
	{
		return userDao.findPage(page);
	}
	public void addOneUser(User user)
	{
		this.saveByAutoUUID(user);
	}
	public void updateOneUser(User user)
	{
		this.update(user);
	}
	@Transactional
	public void saveOrUpdateUser(User user)
	{
		this.saveOrUpdate(user);
	}
	public void deleteUser(String userID)
	{	
		this.delete(userID);
	}
	public User getUserObject(String userID)
	{
		User user = this.getObject(userID);
		return user;
	}
	public User getNowUser()
	{
		return SSUtils.getCurUser();
	}
	public String testOne()
	{
		return "...................";
	}
	public static void main(String[] args)
	{
		UserService userService = AppUtils.getBean(UserService.class);
		for(int i= 0 ;i<10;i++)
		{
			User user =new User();
			user.setAge(1000);
			user.setCreateTime(new Date());
			user.setCreator("abc"+i+"...");
			user.setEditor("test"+i+"...");
			user.setEditTime(new Date());
			user.setIsvalid(1);
			user.setLoginName("admin"+i);
			user.setPassword("admin"+i);
			user.setRegisterTime(new Date());
			user.setSex(1);
			user.setUserName("abc"+i+".....");
			userService.saveOrUpdateUser(user);
		}
//		User user =new User();
//		user.setAge(1000);
//		user.setCreateTime(new Date());
//		user.setCreator("abc...");
//		user.setEditor("test...");
//		user.setEditTime(new Date());
//		user.setIsvalid(1);
//		user.setLoginName("admin");
//		user.setPassword("admin");
//		user.setRegisterTime(new Date());
//		user.setSex(1);
//		user.setUserName("abc.....");
//		user.setUserID("2f575d60-89cd-454b-a39a-598c08fc33c5");
//		User user = userService.getUserObject("10a284e4-589b-47da-bf9d-94f3e2deb95f");
//		System.out.println(user.getLoginName());
	}
}
